<template>
  <el-dialog
    top="30px"
    width="800px"
    append-to-body
    title="日志"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :before-close="beforeClose"
  >
    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:content="scope">
        <div class="text-truncate" :title="scope.row.content">{{ scope.row.content }}</div>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="tableCount"
        @current-change="getData"
      ></el-pagination>
    </div>
  </el-dialog>
</template>

<script>
import { dateFormat } from '@/common/utils/common'
export default {
  props: {
    visible: Boolean,
    userId: String,
  },
  data() {
    return {
      params: {
        index: 1,
        size: 10,
      },
      order: { create_time: 'desc' },
      loading: false,
      tableCount: 0,
      tableColumns: [
        {
          attrs: { label: '时间', prop: 'create_time', align: 'center', width: 170 },
          process: v => dateFormat(v, 'yyyy-MM-dd hh:mm'),
        },
        { attrs: { label: '日志详情', align: 'center' }, slot: 'content' },
      ],
      tableData: [],
    }
  },

  watch: {
    userId: {
      handler: function () {
        this.getData()
      },
      immediate: true,
    },
  },

  created() {},
  methods: {
    getData() {
      if (!this.userId) {
        return
      }
      this.params['user_id.eq'] = this.userId
      this.loading = true
      this.$api
        .getData('credit', 'work_log', this.params, this.order)
        .then(res => {
          this.tableData = (res && res.data && res.data.data) || []
          this.tableCount = (res && res.data && res.data.totalCount) || 0
        })
        .finally(() => {
          this.loading = false
        })
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
  },
}
</script>
<style lang="scss" scoped></style>
